// 导入需要的config和request
import confing from '../../config/config.js';
import request from '../../util/request.js';


// 申明请求对象
const unitmeasureRequest = {
    // itemtype请求的基本url
    BASE_URL: confing.SYS_URL + "/unitmeasure",

    list(page = 1, limit = 10, unitmeasure, callbcak) {
        // url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit;
        if (unitmeasure) {
            if (unitmeasure.measureCode) {
                url += "&measureCode=" + unitmeasure.measureCode;
            }
            if (unitmeasure.measureName) {
                url += "&measureName=" + unitmeasure.measureName;
            }
            if (unitmeasure.primaryFlag) {
                url += "&primaryFlag=" + unitmeasure.primaryFlag;
            }
            if (unitmeasure.changeRate) {
                url += "&changeRate=" + unitmeasure.changeRate;
            }
            if (unitmeasure.enableFlag) {
                url += "&enableFlag=" + unitmeasure.enableFlag;
            }
        }
        // 发送请求
        request.get(url, callbcak);
    },

    /**
* 保存单位
* @param {*} unitmeasure  单位对象
* @param {*} callback  回调函数
*/
    saveUnitmeasure(unitmeasure, callback) {
        let url = this.BASE_URL + "/save";
        request.post(url, unitmeasure, callback);
    },


    /**
 * 根据id加载单位信息
 * @param {*} unitmeasureId 单位编号
 * @param {*} callback 回调函数
 */
    get(measureId, callback) {
        if (measureId) {
            // 准备url
            let url = this.BASE_URL + "/get?measureId=" + measureId;
            request.get(url, callback);
        }
        // 如果没有unitmeasureId，不做任何处理
    },
    /**
 * 根据ID编辑单位信息
 * @param {} unitmeasure 
 * @param {*} callback  
 */
    edit(unitmeasure, callback) {
        if (unitmeasure != undefined && unitmeasure.measureId != undefined) {
            request.put(this.BASE_URL + "/update", unitmeasure, callback);
        }
    },


    /**
 * 根据ID删除客户
 * @param {*} measureId 
 * @param {*} callback 
 */
    delete(measureId, callback) {
        request.delete(this.BASE_URL + "/" + measureId, callback);
    },




 


}
// 将itemtypeRequest暴漏出去
export default unitmeasureRequest;